import React, { Component } from 'react';
import {Switch,Route,Redirect, Router} from "react-router-dom"
class RouterView extends Component {
    render() {
      let {routes} = this.props;
      let myRoutes = routes.filter(v=>!v.redirect&&v.path!=="*")
      let myRedirect = routes.filter(v=>v.redirect)
      let myArr = routes.filter(v=>v.path==="*")
        return (
            <Switch>
                {
                    myRoutes.map((v,i)=>{
                        return (
                            <Route path={v.path} key={i} render={(props)=>{
                                 if(v.children){
                                     return <v.component routes={v.children} {...props}></v.component>
                                 }else{
                                     return <v.component {...props}></v.component>
                                 }
                            }}></Route>
                        )
                    })
                }
                {
                    myRedirect.map((v,i)=>{
                        return <Redirect key={i} from={v.path} to={v.redirect}></Redirect>
                    })
                }
                {
                    myArr.map((v,i)=>{
                        return <Route path={v.path} component={v.component} key={i}></Route>
                    })
                }
            </Switch>
        );
    }
}

export default RouterView;